package com.qianfeng.service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qianfeng.dto.Page;
import com.qianfeng.entity.Student;
import com.qianfeng.entity.Subject;
import com.qianfeng.mapper.StudentMapper;
import com.qianfeng.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Transactional
@Service
public class StudentServiceImpl implements StudentService {

    @Autowired
    private StudentMapper studentMapper;


    @Override
    public void addStudent(Student student) {
        studentMapper.addStudent(student);
    }

    @Override
    public List<Student> getListByStudentId(Integer studentId) {
        List<Student> listByStudentId = studentMapper.getListByStudentId(studentId);

        return listByStudentId;
    }

    @Override
    public void deleteStudent(Integer studentId) {
        studentMapper.deleteStudent(studentId);
    }

    @Override
    public void updateStudent(Student student) {
        studentMapper.updateStudent(student);
    }

    @Override
    public Page getStudentPage(Integer pageNo, Integer pageSize) {
        PageHelper.startPage(pageNo,pageSize);
        List<Student> studentList = studentMapper.getStudentList();
        Page page = new Page();
        PageInfo<Student> pageInfo = new PageInfo<>(studentList);
        page.setCount(pageInfo.getTotal());
        page.setObj(pageInfo.getList());
        page.setPages(pageInfo.getPages());
        return page;
    }
}
